<?php


namespace app\index\console;


use app\common\model\Model;
use app\common\model\User;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Test extends Command
{
    static $instance = null;
    static function inatance(){
        if(empty(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }
    // 定义命令提示和参数
    protected function configure()
    {
        parent::configure();
        $this->setName("test")->setDescription("test  code");
        //具体用法请自行查看thinkphp/library/think/console/command/Command.php
    }

    // 执行命令
    protected function execute(Input $input, Output $output)
    {
        $output->writeln('input command2:');
        $handle = fopen("php://stdin","r");
        $input = trim(fgets($handle));
        $output->writeln('Output: '.$input);
        $instance = self::inatance();
        if(method_exists($instance,$input)){
            $resp = call_user_func([$instance,$input]);
            $output->writeln('result: '.$resp);
        }
    }

    function hello(){
        return "hello world!!!";
    }

    function create_table0(){
        $list = [
            \app\common\model\Server::class,
            \app\common\model\Payment::class,
            \app\common\model\AdminPermission::class,
            \app\common\model\AdminRole::class,
            \app\common\model\AdminRolePermission::class,
            \app\common\model\CoreGood::class,
            \app\common\model\CoreOrder::class,
            \app\common\model\CorePurchase::class,
            \app\common\model\Employ::class,
            \app\common\model\EmployPurchase::class,
            \app\common\model\EmployPurchaseOrder::class,
            \app\common\model\Server::class,
            \app\common\model\ServerGood::class,
            \app\common\model\ServerOrder::class,
            \app\common\model\User::class,
            \app\common\model\UserAttachment::class,
            \app\common\model\UserAttachmentGroup::class,
            \app\common\model\UserAudit::class,
            \app\common\model\UserDetail::class,
            \app\common\model\UserMoney::class,
            \app\common\model\UserMsg::class,
        ];
        /** @var Model $db */
        foreach ($list as $db){
            $db::dropTable();
            $db::createTable();
        }
    }
    function create_table1(){
        $list = [
            \app\common\model\User::class,
        ];
        /** @var Model $db */
        foreach ($list as $db){
            $db::dropTable();
            $db::createTable();
        }
    }
    function register(){
        User::registerSuccess([
            "is_admin"=>1,
            "user_name"=>"root",
            "password"=>"root"
        ]);
        echo "register !";
    }
}